﻿@model Model.FunctionInfo
@{
    ViewBag.Title = "编辑函数";
    Layout = "~/Views/Shared/_Main.cshtml";
}
@section Head{
    <script type="text/javascript">
        $(function () {
            $.post("/SystemConfiguration/BindDropwown/?keyName=ActionType", function (result) {
                var arr_sel = new Array();
                if (result != "") {
                    for (var i = 0; i < result.length; i++) {
                        arr_sel.push("<option value='");
                        arr_sel.push(result[i].Value);
                        arr_sel.push("'>");
                        arr_sel.push(result[i].Name);
                        arr_sel.push("</option>");
                    }
                    $("#ActionType").append(arr_sel.join(""));
                    $("#ActionType").val("@Model.ActionType");
                }
            });
        });

        function btnSave_Click() {
            submitForm();
        }

        function btnClose_Click() {
            returnParent(null);
        }
        //----------提交数据 ----------------
        function submitForm() {
            if ($('#ff').form("validate")) {
                if ($.trim($('#FunName').val()) == "") {
                    alert("函数名称不能为空！");
                    return false;
                }
                var result = $("#FunName").val().match(/^\w+$/);
                if (result == null) {
                    alert("函数名称格式不正确，只能由数字、英文字母或者下划线组成!");
                    return false;
                }
                if ($.trim($('#ActionType').val()) == "") {
                    alert("功能类型不能为空！");
                    return false;
                }
                var postUrl = "/Function/Update";
                var postData = $('#ff').serialize();
                $.ajax({
                    type: "POST",
                    async: true,
                    url: postUrl,
                    data: postData,
                    success: function (result) {
                        if (result.Success == true) {
                            alert(result.Message);
                            btnClose_Click();
                        }
                        else {
                            alert(result.Message);
                        }
                    }
                });
            }
        }
        //----------提交数据 END----------------
    </script>
}
<div style="margin: 5px;">
    <form id="ff" method="post">
    @{
        // 渲染输出列表
        var dataToolbar = new ViewDataDictionary();
        dataToolbar.Add("PanelTitle", "编辑函数");
        dataToolbar.Add("GridID", "DataGrid");
        dataToolbar.Add("ShowAddButton", false);
        dataToolbar.Add("ShowDeleteButton", false);
        dataToolbar.Add("ShowSaveButton", true);
        dataToolbar.Add("ShowOtherButton", false);
        dataToolbar.Add("ShowBackButton", false);
        dataToolbar.Add("ShowCloseButton", true);
        dataToolbar.Add("ShowPager", true);
        dataToolbar.Add("ShowLoading", true);
        @Html.Partial("_ToolBarPanel", dataToolbar);
    }
    @Html.HiddenFor(model => model.Guid)
    <table class="table_bg" style="width: 100%;" cellpadding="0" cellspacing="0">
        <tr>
            <td style="text-align: right; width: 100px;">
                <span class="red">*</span>函数名称：
            </td>
            <td>
                @Html.TextBoxFor(model => Model.FunName, new { style = "Width: 400px;" })
            </td>
        </tr>
        <tr>
            <td style="text-align: right; width: 100px;">
                <span class="red">*</span>参数数量：
            </td>
            <td>
                <input id="ParamCount" name="ParamCount" style="width: 100px;" type="text" value="@Model.ParamCount" onkeyup="this.value=checkNum(this.value)" />
            </td>
        </tr>
        <tr>
            <td style="width: 100px; text-align: right;">
                <span class="red">*</span>函数类型：
            </td>
            <td>
                @{
                    var funTypeList = new List<SelectListItem>();
                    funTypeList.Add(new SelectListItem() { Value = "1", Text = "表值函数" });
                    funTypeList.Add(new SelectListItem() { Value = "2", Text = "标量值函数" });
                    funTypeList.Add(new SelectListItem() { Value = "3", Text = "聚合函数" });
                    funTypeList.Add(new SelectListItem() { Value = "4", Text = "系统函数" });
                    @Html.DropDownListFor(model => model.FunType, funTypeList, new { style = "Width: 100px;" });
                }
            </td>
        </tr>
        <tr>
            <td style="text-align: right; width: 100px;">
                <span class="red">*</span>功能类型：
            </td>
            <td>
            <select id="ActionType" name="ActionType" style = "Width: 100px;">
            <option value="">-请选择-</option>
            </select>
            </td>
        </tr>
        <tr>
            <td style="text-align: right;" valign="top">
                函数描述：
            </td>
            <td>
                @Html.TextAreaFor(model => Model.Description, new { style = "Width: 400px; Height: 150px;" })
            </td>
        </tr>
    </table>
    </form>
</div>
